<?php

namespace App\Listeners;

use App\Events\MasterOrderRefund;
use App\Events\OrderRefund;
use App\Services\ISystemService;
use Illuminate\Cache\Events\CacheHit;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Log;

class MasterOrderRefundListener implements ShouldQueue
{

    use InteractsWithQueue;

    public $queue = 'finance';

    public $tries = 3;

    public $timeout = 30;

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  CacheHit  $event
     * @return void
     */
    public function handle(MasterOrderRefund $event)
    {
        resolve(ISystemService::class)->requestApi(config('common.api_domain')."/api/event/masterorderrefund/{$event->refund_id}",['ip'=>$event->ip],'POST');
    }

    public function failed(MasterOrderRefund $event, \Exception $exception)
    {
        Log::error("System request api error: ".$exception->getMessage());
    }
}
